import { Module } from '@nestjs/common';
import { AppController } from './app.controller';
import { AppService } from './app.service';
import { PostsModule } from './posts/posts.module';
import { TypeOrmModule } from '@nestjs/typeorm';
import { ConfigService, ConfigModule } from '@nestjs/config';
import envConfig from '../config/env';
import { UserModule } from './user/user.module';
import { AuthModule } from './auth/auth.module';
import { CategoryModule } from './category/category.module';
import { TagModule } from './tag/tag.module';
import { UserinfoModule } from './userinfo/userinfo.module';
@Module({
  imports: [
    ConfigModule.forRoot({ isGlobal: true, envFilePath: [envConfig.path] }),
    ConfigModule.forRoot({ isGlobal: true }),
    // TypeOrmModule.forRootAsync({
    //   inject: [ConfigService],
    //   useFactory: async (configService: ConfigService) => ({
    //     type: 'mysql',
    //     host: configService.get('DB_HOST', '127.0.0.0'),
    //     port: configService.get<number>('DB_PORT', 3306),
    //     username: configService.get('DB_USER', 'root'),
    //     password: configService.get('DB_PASSWORD', 'root'),
    //     database: configService.get('DB_DATABASE', 'blog'),
    //     // charset: 'utf8mb4',
    //     timezone: '+08:00',
    //     synchronize: true,
    //     autoLoadEntities: true
    //   }),
    // }),
    TypeOrmModule.forRoot({
      type: 'mysql',
      host: 'localhost',
      port: 3306,
      username: 'root',
      password: 'root',
      database: 'blog',
      // charset: 'utf8mb4',
      timezone: '+08:00',
      synchronize: true,
      autoLoadEntities: true
    }),
    PostsModule,
    UserModule,
    AuthModule,
    CategoryModule,
    TagModule,
    UserinfoModule
  ],
  controllers: [AppController],
  providers: [AppService],
})
export class AppModule { }
